package com.rmuti.programming.testswt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class TestUI4 {

	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
		shell.open();
		shell.setBackgroundMode(SWT.INHERIT_FORCE);
		shell.setBounds(400, 120, 385, 390);
		shell.setBackground(display.getSystemColor(SWT.COLOR_GRAY));

		shell.addPaintListener(new PaintListener() {

			@Override
			public void paintControl(PaintEvent e) {
				e.gc.fillRoundRectangle(10, 10, 90, 45, 25, 15);
			}
		});

		createHeaderMenu(display, shell);

		Composite composite = new Composite(shell, SWT.NONE);
		composite.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
		composite.setBounds(0, 100, 385, 170);

		Label name = new Label(composite, SWT.NONE);
		name.setText("ชื่อ เฉลิมวุฒิ น้อยอุ่นแสน");
		name.pack();
		
		Label score = new Label(composite, SWT.NONE);
		score.setText("คะแนนที่ได้ 8 เต็ม 10");
		score.setBounds(40, 40, 150, 40);

		createButtomMenu(display, shell);

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();

	}

	private static void createButtomMenu(final Display display,
			final Shell shell) {
		Image bg = new Image(display, "icons/image/header.gif");
		Composite composite = new Composite(shell, SWT.NONE);
		composite.setBackgroundMode(SWT.INHERIT_FORCE);
		composite.setBackgroundImage(bg);
		composite.setBounds(0, 335, 385, 55);

		Button backButton = new Button(composite, SWT.PUSH);
		backButton.setText("กลับ");
		backButton.setSize(50, 35);
		backButton.setLocation(110, 8);
		backButton.addListener(SWT.Selection, new Listener() {

			@Override
			public void handleEvent(Event event) {
				shell.close();
			}
		});

		Button button = new Button(composite, SWT.PUSH);
		button.setText("ส่งคะแนน");
		button.setSize(80, 35);
		button.setLocation(180, 8);
	}

	private static void createHeaderMenu(final Display display,
			final Shell shell) {
		Image bg = new Image(display, "icons/image/header.gif");
		Composite composite = new Composite(shell, SWT.NONE);
		composite.setBackgroundImage(bg);
		composite.setBackgroundMode(SWT.INHERIT_FORCE);
		composite.setBounds(0, 0, 385, 55);

		Label label1 = new Label(composite, SWT.NONE);
		label1.setText("ปฏิบัติการเขียนโปรแกรม");
		label1.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
		label1.setLocation(110, 12);
		label1.pack();
	}
}
